---
layout: "default"
title: "String.UnicodeScalarView.UnicodeScalarIndex"
description: "Swift documentation for extension 'String.UnicodeScalarView.UnicodeScalarIndex'."
keywords: "String.UnicodeScalarView.UnicodeScalarIndex,extension,swift,documentation,samePositionIn,samePositionIn,samePositionIn"
root: "/v2.2"
---

<div class="intro-declaration"><code class="language-swift">extension String.UnicodeScalarView.UnicodeScalarIndex</code></div>


<table class="standard">



<tr>
<th>Import</th>
<td><code class="language-swift">import Swift</code></td>
</tr>

</table>


<h3>Initializers</h3>
<div class="declaration" id="init_within_">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_within_">init(<wbr>_:<wbr>within:)</a><div class="comment collapse" id="comment-init_within_"><div class="p">
    <p>Construct the position in <code>unicodeScalars</code> that corresponds
exactly to <code>characterIndex</code>.</p>

<p><strong>Requires:</strong> <code>characterIndex</code> is an element of
  <code>String(unicodeScalars).indices</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init(_ characterIndex: Index, within unicodeScalars: String.UnicodeScalarView)</code>

    </div></div>
</div>
<div class="declaration" id="init_-utf8index-within_-string-unicodescalarview">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-utf8index-within_-string-unicodescalarview">init?(<wbr>_:<wbr> UTF8Index, within: String.UnicodeScalarView)</a><div class="comment collapse" id="comment-init_-utf8index-within_-string-unicodescalarview"><div class="p">
    <p>Construct the position in <code>unicodeScalars</code> that corresponds exactly to
<code>utf8Index</code>. If no such position exists, the result is <code>nil</code>.</p>

<p><strong>Requires:</strong> <code>utf8Index</code> is an element of
  <code>String(unicodeScalars).utf8.indices</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init?(_ utf8Index: UTF8Index, within unicodeScalars: String.UnicodeScalarView)</code>

    </div></div>
</div>
<div class="declaration" id="init_-utf16index-within_-string-unicodescalarview">
<a class="toggle-link" data-toggle="collapse" href="#comment-init_-utf16index-within_-string-unicodescalarview">init?(<wbr>_:<wbr> UTF16Index, within: String.UnicodeScalarView)</a><div class="comment collapse" id="comment-init_-utf16index-within_-string-unicodescalarview"><div class="p">
    <p>Construct the position in <code>unicodeScalars</code> that corresponds exactly to
<code>utf16Index</code>. If no such position exists, the result is <code>nil</code>.</p>

<p><strong>Requires:</strong> <code>utf16Index</code> is an element of
  <code>String(unicodeScalars).utf16.indices</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">init?(_ utf16Index: UTF16Index, within unicodeScalars: String.UnicodeScalarView)</code>

    </div></div>
</div>





<h3>Instance Methods</h3>
<div class="declaration" id="func-samepositionin_-string">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-samepositionin_-string">func samePositionIn(<wbr>_: String)</a>
        
<div class="comment collapse" id="comment-func-samepositionin_-string"><div class="p">
    <p>Returns the position in <code>characters</code> that corresponds exactly
to <code>self</code>, or if no such position exists, <code>nil</code>.</p>

<p><strong>Requires:</strong> <code>self</code> is an element of <code>characters.unicodeScalars.indices</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func samePositionIn(characters: String) -&gt; Index?</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-samepositionin_-string-utf8view">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-samepositionin_-string-utf8view">func samePositionIn(<wbr>_: String.UTF8View)</a>
        
<div class="comment collapse" id="comment-func-samepositionin_-string-utf8view"><div class="p">
    <p>Returns the position in <code>utf8</code> that corresponds exactly
to <code>self</code>.</p>

<p><strong>Requires:</strong> <code>self</code> is an element of <code>String(utf8)!.indices</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func samePositionIn(utf8: String.UTF8View) -&gt; String.UTF8View.Index</code>
    
    
</div></div>
</div>
<div class="declaration" id="func-samepositionin_-string-utf16view">
<a class="toggle-link" data-toggle="collapse" href="#comment-func-samepositionin_-string-utf16view">func samePositionIn(<wbr>_: String.UTF16View)</a>
        
<div class="comment collapse" id="comment-func-samepositionin_-string-utf16view"><div class="p">
    <p>Returns the position in <code>utf16</code> that corresponds exactly
to <code>self</code>.</p>

<p><strong>Requires:</strong> <code>self</code> is an element of <code>String(utf16)!.indices</code>.</p>

    <h4>Declaration</h4>    
    <code class="language-swift">func samePositionIn(utf16: String.UTF16View) -&gt; String.UTF16View.Index</code>
    
    
</div></div>
</div>


